var username = $("#username");
var password = $("#password");
function validate(){
	if(validateUsername()&&validatePassword()){
        $.ajax({
            dataType:"json",
            type:"POST",
            url:"/login",
            data:{
                phoneNumber:username.val(),
                password:password.val(),
            },
            error:function () {
                console.log("error");
            },
            success:function(msg){
                if(msg.status=="101"){
                    $("#error").html("<span>用户名或密码错误</span>");
                }else{
                    window.location.href = "index.jsp";
                }
            }
        });
    }
    return false;
}
function validateUsername(){
    var value = username.val();
    var regu = /^[1][0-9][0-9]{9}$/;
    var re = new RegExp(regu);
    if (re.test(value)) {
    	username.removeClass("unvalid");
        return true;
    } else {
        username.addClass("unvalid");
        return false;
    }
}

function validatePassword() {
	var value = password.val();
	if(value==""){
        password.addClass("unvalid");
        return false;
	}else {
		password.removeClass("unvalid");
		return true;
	}
}
window.onload = function (){
    $("#checkboxG1").change(function () {
        var password = $("#password");
        if($(this).is(':checked')){
            password.attr("type","text");
        }else {
            password.attr("type","password");
        }
    });
}